feat(currency): Introduce try_new_code constructors and IsoName fallback#8229
Merged
Conversation
younies
force-pushed
the
currency-iso-formatting
branch
from
July 14, 2026 14:21
2c83b9a to
9416f65
Compare
younies
force-pushed
the
currency-iso-formatting
branch
from
July 14, 2026 14:57
9416f65 to
2498c10
Compare
younies
marked this pull request as ready for review
July 16, 2026 13:28
younies
requested review from
a team,
Manishearth,
robertbastian and
sffc
as code owners
July 16, 2026 13:28
robertbastian
left a comment
Member
There was a problem hiding this comment.
this should be done after #8235
…llback Introduce try_new_code, try_new_compact_code, and try_new_compact_long_code constructors for formatting with 3-letter ISO currency codes (e.g. USD, EUR) without requiring the CurrencySymbolsV1 data payload, completing the 12-constructor matrix. - Adapt standard symbol ISO fallback by directly producing CurrencyFormatterData::Iso in try_new_code constructors. - Add CurrencyFormatterData::IsoExtended variant and adapt try_new_name to fall back cleanly to IsoExtended when long currency display names are missing, eliminating optional DataPayloads in enum variants. - Add test_code and test_name_fallback_to_iso_extended unit tests verifying ISO code formatting and long name fallback behaviors. TAG=agy CONV=f93d26e4-1f87-41f6-88d1-9069dadd73ee
younies
force-pushed
the
currency-iso-formatting
branch
from
July 21, 2026 12:25
2498c10 to
9ab4c5a
Compare
Rename CurrencyFormatterData::IsoExtended to IsoName to make it clear that it represents the fallback representation for full display name formatting. TAG=agy CONV=f93d26e4-1f87-41f6-88d1-9069dadd73ee
When full display name formatting falls back to an invariant ISO currency code (IsoName), evaluating cardinal plural rules is unnecessary since ISO codes do not decline by grammatical count. - Remove plural_rules field from CurrencyFormatterData::IsoName. - Avoid loading PluralRules when long display names are absent during try_new_name initialization. - Use default unit pattern (other) directly when styling IsoName expressions. TAG=agy CONV=f93d26e4-1f87-41f6-88d1-9069dadd73ee
Member
Author
|
@robertbastian : you can review this now |
robertbastian
approved these changes
Jul 21, 2026
| #[cfg(feature = "compiled_data")] | ||
| pub fn try_new_compact_code( | ||
| prefs: CurrencyFormatterPreferences, | ||
| currency_code: &CurrencyCode, |
Member
There was a problem hiding this comment.
issue, pre-existing: we should take CurrencyCode by value, it's a small Copy struct
| let value = "12345.67".parse().unwrap(); | ||
|
|
||
| let fmt_code_en = CurrencyFormatter::try_new_code(prefs_en, ¤cy_usd).unwrap(); | ||
| assert_writeable_eq!( |
|
|
||
| #[derive(Debug)] | ||
| pub(crate) enum CurrencyFormatterData { | ||
| Iso { |
Member
Author
|
applying all the comments in a following PR to rebase the other PRs |
robertbastian
pushed a commit
that referenced
this pull request
Jul 21, 2026
… to IsoSymbol (#8246) Address review feedback left on #8229 from @robertbastian: - Change all `try_new_*` constructor signatures in `CurrencyFormatter` to take `CurrencyCode` by value instead of by reference (`CurrencyCode` is a small `Copy` struct). - Rename `CurrencyFormatterData::Iso` enum variant to `IsoSymbol` for clarity and symmetry with `IsoName`. - Add unit test coverage (`test_compact_code`) for both short and long compact ISO currency code formatting.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduce
try_new_codeconstructor family for formatting with 3-letter ISO currency codes (e.g.USD,EUR) without requiring symbol data payloads, completing the 12-constructor matrix across standard and compact formatting.Key Changes
try_new_code): Implementtry_new_code,try_new_compact_code, andtry_new_compact_long_code(and their compiled/buffer/unstable variants). These explicitly constructCurrencyFormatterData::Iso, adapting standard symbol fallback layout without requiringCurrencySymbolsV1data payloads.IsoNameFallback): AddCurrencyFormatterData::IsoNameto eliminateOption<DataPayload>in full display name formatters (Name). Whentry_new_nameencounters missing localized display names, it cleanly falls back toIsoName, bypassing unnecessaryPluralRulesinstantiation and styling with default unit patterns.format.rs(test_codeandtest_name_fallback_to_iso_name) verifying ISO code formatting and graceful fallback behavior.Changelog
try_new_codeconstructors for explicit ISO code formatting across decimal and compact currency formatters.IsoNamefallback variant intry_new_nameto remove optional payload overhead when long currency display names are absent.TAG=agy
CONV=f93d26e4-1f87-41f6-88d1-9069dadd73ee